<template>
<!--remao_shop/packageC/integralTransfer/integralTransfer.wxml-->
<view class="content">
  <form class="con">
      <view class="title-p">请填写申请信息</view> 
      <view class="message">
         <text>会员名:</text>
         <input type="text" @input="nameFun" placeholder="请填写会员名"></input>
      </view>
      <view class="message">
         <text>转入积分:</text>
         <input type="number" @input="phoneFun" placeholder="请填写积分"></input>
      </view>
      <button class="but" hover-class="none" @tap="DistributionCenter">提交申请</button>
   </form>
</view>
</template>

<script>
// remao_shop/packageC/integralTransfer/integralTransfer.js
var app = getApp();
import api from "../../../api";

export default {
  data() {
    return {
      uid: '',
      name: '',
      phone: ''
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getStorage({
      key: 'userId',
      success: res => {
        console.log(res);
        this.setData({
          uid: res.data
        });
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    //获取输入的名称号码
    nameFun(e) {
      console.log(e.detail.value);
      this.setData({
        name: e.detail.value
      });
    },

    phoneFun(e) {
      console.log(e.detail.value);
      this.setData({
        phone: e.detail.value
      });
    },

    DistributionCenter: function () {
      if (this.name == '') {
        wx.showToast({
          title: '请输入会员名',
          icon: 'none'
        });
      } else if (this.phone == '') {
        wx.showToast({
          title: '请输入转入积分',
          icon: 'none'
        });
      } else {
        app.globalData.request({
          url: api.default.transmit,
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          data: {
            u_id: this.uid,
            nickname: this.name,
            num: this.phone
          },
          method: 'POST',
          success: res => {
            console.log(res);

            if (res.status == 1) {
              if (res.msg == "提交成功") {
                wx.showToast({
                  title: res.msg
                });
                setTimeout(function () {
                  wx.navigateBack({
                    delta: 1
                  });
                }, 1500);
              } else {
                wx.showToast({
                  title: res.msg,
                  icon: 'none'
                });
                setTimeout(function () {
                  wx.navigateBack({
                    delta: 1
                  });
                }, 1500);
              }
            } else {
              wx.showToast({
                title: res.msg,
                icon: 'none'
              });
            }
          }
        });
      }
    }
  }
};
</script>
<style>
@import "./integralTransfer.css";
</style>